package screen.component
{
	import com.adobe.serialization.json.JSON;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.text.TextField;
	
	import helper.Services;
	import helper.ValueObject;
	
	import screen.TechComBankScreen;

	public class Option extends Popup
	{
		private var _tech_com_bank_screen:TechComBankScreen;
		public function Option()
		{
			init();
		}
		private function init():void{
			_tech_com_bank_screen = TechComBankScreen.getInstance();
			_popup = ValueObject.T1_RESOURCE.getExportedAsset("optionPopup") as MovieClip;
			buttonImageInit(_popup.playBtn);
			MovieClip(_popup.playBtn).addEventListener(MouseEvent.CLICK,_tech_com_bank_screen.playBtnHandle);
			buttonImageInit(_popup.helpBtn);
			MovieClip(_popup.helpBtn).addEventListener(MouseEvent.CLICK,_tech_com_bank_screen.helpBtnHandle);
			popupInit(_popup);
			Services.getInstance().getReward(getRewardComplete,getRewardError);
		}
		private function getRewardComplete(e:Event):void{
			URLLoader(e.target).removeEventListener(Event.COMPLETE,getRewardComplete);
			URLLoader(e.target).removeEventListener(IOErrorEvent.IO_ERROR,getRewardError);
			var no:Number = JSON.decode(e.target.data);
			if(no>0){
				TextField(_popup.rewardTf).text =  "Chúc mừng, bạn được thưởng "+ no +" điểm vì quay lại game!"
			}else{
				TextField(_popup.rewardTf).text = ""
			}
			show();
		}
		private function getRewardError(e:IOErrorEvent):void{
			trace("getRewardError:");
			URLLoader(e.target).removeEventListener(Event.COMPLETE,getRewardComplete);
			URLLoader(e.target).removeEventListener(IOErrorEvent.IO_ERROR,getRewardError);
			show();
		}
	}
}